
var router = require('express').Router();

var User = require('../modules/db/user');

router.get('/user', (req, res)=>{
    if (!req.session.user) {
        res.json({ 
            error: 1, 
            txt: '请先登录' 
        });
        return;
    } 
    User.findOne({_id: req.session.user._id}, (err, user)=>{
        res.json({
            error: 0,
            user: JSON.parse(JSON.stringify(user))
        });
    });
});


router.get('/logout', (req, res)=>{
    delete req.session.user;
    res.json({
        error: 0, 
        txt: '退出登录'
    });
});

module.exports = router;